package cn.group01.git.controller;

import cn.group01.git.annotations.LogOperation;
import cn.group01.git.common.Operation;
import cn.group01.git.common.ResponseResult;
import cn.group01.git.dto.SupplierPageDTO;
import cn.group01.git.entity.Supplier;
import cn.group01.git.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description:
 * @author: 叶晓龙
 * @date: 2023/7/13 11:14
 **/
@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    // 供应商下拉列表的展示
    @GetMapping("supList")
    @LogOperation(description = Operation.OTHER,model = "供应商模块")
    public ResponseResult supList(){
       return supplierService.supList();
    }

    // 供应商界面的回显
    @GetMapping("list")
    @LogOperation(description = Operation.SELECT,model = "供应商模块")
    public ResponseResult getList(SupplierPageDTO supplierPageDTO){
        return supplierService.getList(supplierPageDTO);
    }

    // 供应商界面的回显
    @PostMapping("add")
    @LogOperation(description = Operation.ADD,model = "供应商模块")
    public ResponseResult addSupplier(@RequestBody Supplier supplier){
        return supplierService.addSupplier(supplier);
    }

    // 编辑界面回显
    @GetMapping("getById")
    @LogOperation(description = Operation.OTHER,model = "供应商模块")
    public Supplier getById(Integer supId){
        return supplierService.getById(supId);
    }

    @PostMapping("edit")
    @LogOperation(description = Operation.UPDATE,model = "供应商模块")
    public ResponseResult editSupplier(@RequestBody Supplier supplier){
        return supplierService.editSupplier(supplier);
    }

    // 删除和批量删除
    @GetMapping("delete")
    @LogOperation(description = Operation.DELETE,model = "供应商模块")
    public ResponseResult delete(Integer ids[]){
        return supplierService.delete(ids);
    }

    // 供应商批量导入
    @PostMapping("batch")
    //@LogOperation(description = Operation.ADD,model = "供应商批量导入")
    public ResponseResult addSuppliers(MultipartFile file){
        return supplierService.batchAdd(file);
    }
}
